<?php


namespace app\badmin\model;


use app\common\model\BaseModel;

class CompanyAgentUser extends BaseModel {

    /**
     * 客户详情
     * @param $params
     * @return array|\PDOStatement|string|\think\Model|null
     */
    public static function userInfo($params) {
        $column = ['cau.company,cau.position,cau.province,cau.city,cau.area,cau.birthday,cau.remark,cau.status,cau.phone,cs.name as cs_name,cau.remark_phone,cau.itime'];
        $map[] = ['cau.id', '=', $params['id']];
        $map[] = ['ca.deleted', '=', 0];
        $data = self::getOne($map, $column);
        if (empty($data)) {
            $data = [];
        } else {
            $data ['address'] = $data['province'] . $data['city'] . $data['area'];
            $data ['birthday'] = !empty($data ['birthday']) ? date('Y.m.d', $data ['birthday']) : '';
            $data ['status'] = CompanyUser::$status[$data ['status']];
            $data ['itime'] = date('Y-m-d H:i:s', $data ['itime']);
            unset($data['province']);
            unset($data['city']);
            unset($data['area']);
        }
        return $data;
    }

    /**
     * 获取单条数据
     * @param $map
     * @param $column
     * @return array|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getOne($map, $column) {
        return db("company_agent_user")
            ->alias('cau')
            ->leftJoin('company_agent ca', 'ca.id = cau.agent_id')
            ->leftJoin('company_shop cs', 'cs.id = ca.company_shop_id')
            ->where($map)
            ->field($column)
            ->find();
    }

}